//
// Source code recreated from a .class file by IntelliJ IDEA
// (powered by FernFlower decompiler)
//

package 力扣.题库.滑动窗口.定长滑动窗口;

public class demo_643 {
    public demo_643() {
    }

    public static void main(String[] args) {
        int[] nums = new int[]{0, 1, 1, 3, 3};
        System.out.println(findMaxAverage(nums, 4));
    }

    public static double findMaxAverage(int[] nums, int k) {
        if (nums.length == 1) {
            return (double)nums[0];
        } else {
            int left = 0;
            int right = k;
            double avg = (double)Integer.MIN_VALUE;
            double sum = (double)0.0F;

            for(int i = 0; i < k; ++i) {
                sum += (double)nums[i];
            }

            for(avg = Math.max(avg, sum / (double)k); right < nums.length; ++right) {
                double var10 = sum - (double)nums[left];
                sum = var10 + (double)nums[right];
                avg = Math.max(avg, sum / (double)k);
                ++left;
            }

            return avg;
        }
    }
}
